import { Injectable, UnauthorizedException } from "@nestjs/common";
import { PassportStrategy } from "@nestjs/passport";
import { Strategy } from "passport-jwt";
import { AuthService } from "../service/auth.service";



@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy){
    constructor(
        private authService:AuthService
    ){
        super({
            usernameField: 'credential',
            passwordField: 'password',
        });
    }
    async validate(credential: string, password: string): Promise<any> {
        const user = await this.authService.validatorUser(credential, password);
        if (!user) {
            throw new UnauthorizedException();
        }
        return user;
    }
}